package penguin.masking.filter;

import penguin.masking.MaskingContext;
import penguin.masking.jdbc.DBMetaHandler;
import penguin.masking.jdbc.MetaHandlerFactory;

import java.sql.ResultSet;
import java.util.List;

/**
 * @author wuxh
 * @version 1.0.0
 */
public class TableFilter implements MaskingFilter {

    @Override
    public boolean doFilter(ResultSet set, Object columnName, int columnIndex) {
        List<String> tables = MaskingContext.context().getTables();
        if (!tables.isEmpty() && columnIndex > 0) {
            DBMetaHandler handler = MetaHandlerFactory.getInstance().handler(set);
            String tableName = handler.tableName(set, columnIndex);
            if (!tables.contains(tableName)) {
                return true;
            }
        }
        return false;
    }

}
